home *** CD-ROM | disk | FTP | other *** search
- Path: ldb.han.de!W.FANDRYCH
- From: W.FANDRYCH@LDB.han.de (Wolfgang H. A. Fandrych)
- Newsgroups: comp.lang.c
- Subject: Re: Reclaiming memory allocated recursively
- Date: 3 Jan 96 12:42:00 +0100
- Message-ID: <60BE3DU0vlB@ldb-wf.ldb.HAN.DE>
- References: <4c8f8q$ln9@yarrow.wt.com.au>
- X-Mailer: CrossPoint v3.02
- X-Gateway: ZCONNECT UH ldb.han.de [UUCPfZ V5.69 U002]
-
- Hi to all and hi to bvarley@yarrow.wt.com.au!
-
- On 02.01.96, you wrote about
- "Reclaiming memory allocated recursively":
-
- > struct node *freetree (struct node *p)
- > {
- > if (p != NULL)
- > {
- > freetree (p -> left) ;
- > free (p -> data_pointer) ;
- > freetree (p -> right) ;
- > }
- > return (0) ;
- > }
- >
- > seems unlikely to work, because the memory required to navigate
- > through the tree is being deallocated as the process proceeds. In
- > fact, the system crashes when I run the routine.
- Why don't you simply change the order of your commands?
- If you call freetree(p -> right) just before you call
- free(p -> data_pointer) you'll free the subtree before deallocating the
- pointer.
-
-
- Bye
- Alwin.
- --
- If you've got an idea Wolfgang Hermann Alwin PGP-Key
- for a nice signature Fandrych available on
- send email to: W.Fandrych@LDB.HAN.DE request
-
-